package zjh_20230328;

import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.util.Arrays;

public class Demo1 {
    public static void main(String[] args) {
        Class<Student> studentClass = Student.class;

        Field[] declaredFields = studentClass.getDeclaredFields();
        for (Field f : declaredFields) {
            System.out.println(f);
        }
        try {
            Student student = studentClass.newInstance();
            Field name = studentClass.getDeclaredField("name");
            name.setAccessible(true);
            name.set(student,"西安");
            name.get(student);
            System.out.println(student);
        } catch (NoSuchFieldException e) {
            throw new RuntimeException(e);
        }  catch (InstantiationException e) {
            throw new RuntimeException(e);
        } catch (IllegalAccessException e) {
            throw new RuntimeException(e);
        }
    }
}
